import React, { PureComponent } from 'react';
import { Form, Button, Select, message } from 'antd';
import moment from 'moment';
import { connect } from 'dva';
import { formatMDate } from '@/utils/dateFormat';

const FormItem = Form.Item;
const Option = Select.Option;
@connect()
class YhglAssignForm extends PureComponent {
  constructor(props) {
    super(props);

    this.state = {};
    this.dispatch = this.props.dispatch;
    this.user_id = sessionStorage.getItem('user_id');
  }

  componentDidMount() {
    var p = this.props;
    var r = p.record;
    this.props.form.setFields({
      cid: {
        value: r.clbm,
      },
    });
  }

  // 点击button
  handleSubmit = e => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        var r = this.props.record;

        this.dispatch({
          type: 'maintain/fetchAssignProblem',
          payload: {
            pid: r.id,
            cid: values.cid,
          },
          callback: response => {
            if (response.status) {
              message.success('分派成功');
              this.props.handleCancel(this.props.modalName);
              this.props.GetQueryProblem(this.props.queryCon);
            } else {
              message.error('分派失败');
              console.log(response.ErrorMessage);
            }
          },
        });
      }
    });
  };

  render() {
    const { getFieldDecorator } = this.props.form;
    var p = this.props;

    return (
      <Form
        layout="inline"
        style={{ textAlign: 'center', padding: '10px' }}
        onSubmit={this.handleSubmit}
      >
        <FormItem label="公司名称">
          {getFieldDecorator('cid')(
            <Select style={{ width: '200px' }}>
              {p.yhdwList
                ? p.yhdwList.map(i => (
                    <Option key={i.Id} value={i.Id}>
                      {i.Name}
                    </Option>
                  ))
                : null}
            </Select>
          )}
        </FormItem>
        <FormItem>
          <Button type="primary" htmlType="submit">
            确定
          </Button>
        </FormItem>
      </Form>
    );
  }
}

const YhglAssignFm = Form.create()(YhglAssignForm);
export default YhglAssignFm;
